package Pet.Management.repository;

import Pet.Management.domain.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface UserRepository extends JpaRepository<User, Long> {
    Optional<User> findByUsername(String username);
    
    // 根据手机号或用户名模糊搜索
    Page<User> findByPhoneContainingOrUsernameContaining(String phone, String username, Pageable pageable);
    
    // 根据实名认证状态查询（通过身份证号是否为空判断）
    @Query("SELECT u FROM User u WHERE (:isAuth = true AND u.idCard IS NOT NULL) OR (:isAuth = false AND (u.idCard IS NULL OR u.idCard = ''))")
    Page<User> findByIdCardIsNotNull(@Param("isAuth") boolean isAuth, Pageable pageable);
} 